--
-- Author: shunguo.chen
-- Date: 2018-01-09 15:38:51
--
-- CosplayBigRender 玩家选择大render

local HeadRender = require("app.widget.renders.HeadRender")

local ClassRef = app.mvc.createRenderClass(...)

function ClassRef.createWithData(data, node)
	local sprite = ClassRef.extend(node)
	if node == nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init(data)
	return sprite
end     
function ClassRef.create(node)
    return ClassRef.createWithData(nil, node)
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._headRender = HeadRender.create(self._ui.head, 3)

	self:refresh()
end

-- data = CosplayChoice
function ClassRef:refresh()
	if self._data then
		if self._data:isChoose() then
			local params = self._data:getRoleAvatarParams()
			self._headRender:setData(params)
			self:setSelected(true, params.name)
		else
			self._headRender:setIconVisible(false)
			self:setSelected(false)
		end
		self:setName(self._data:getUserName())
	end
end

-- data = {targetName=, name=, icon=}
function ClassRef:setBossData(data)
	self._data = data
	self:setName(data.targetName)
	self:setSelected(true, data.name)
	self._headRender:setType(1)
	self._headRender:setIcon(data.icon)
end

function ClassRef:setSelected(b, name)
	self._ui.icon:setVisible(not b)
	if b then
		self._ui.tips:setString(name)
	else
		self._ui.tips:setString(L("lua_code_text_88"))
	end
end

function ClassRef:setName(name)
	self._ui.name:setString(name)
end

function ClassRef:setIsEnemy(b)
	self._headRender:setFaceLeft(b)
end

return ClassRef